package com.halflife.concurrence;

import java.util.concurrent.atomic.AtomicInteger;

public class MutiThreadTest {
    public static AtomicInteger count = new AtomicInteger(0);
    public static volatile int threshold =0;
    public static void main(String[] args) {
//        for (int i = 0; i < 400; i++) {
//            Thread thread = new Thread(()->{
//                while (true) {
//                    try {
//                        if (threshold > 100) {
//                            break;
//                        }
//                        Thread.sleep(1000);
//                        System.out.println(Thread.currentThread().getName());
//                    } catch (InterruptedException e) {
//                        e.printStackTrace();
//                    }
//                }
//            },"Test-Thread" + i);
//            thread.start();
//        }
        while (true) {
            try {
                if (count.incrementAndGet() > 100) {
                    threshold = 500;
//                    if (count.incrementAndGet() > 105) {
//                        break;
//                    }
                }

                Thread.sleep(1000);
                System.out.println(Thread.currentThread().getName());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }


}
